# 需求：打印函数执行耗时
import time
#
# def func():
#     start_time = time.time()
#     print("执行函数func")
#     time.sleep(2)
#     end_time = time.time()
#     print("函数执行耗时：{}".format(end_time-start_time))
#
# func()

# # 装饰器实现：打印函数执行耗时
# def getTime():
#     def inner(func):
#         start_time = time.time()
#         func()
#         end_time = time.time()
#         print("函数执行耗时：{}".format(end_time-start_time))
#     return inner
#
# @getTime()
# def func_1():
#     print("执行函数func")
#     time.sleep(2)

# # 函数需要参数装饰器怎么写
# def getTime(func):
#     def inner(*args, **kwargs):
#         start_time = time.time()
#         func(*args, **kwargs)
#         end_time = time.time()
#         print("函数执行耗时：{}".format(end_time-start_time))
#     return inner
#
# @getTime
# def addNum(a, b):
#     print("计算结果是：{}".format(a+b))
#     time.sleep(2)
#
# addNum(10, 15)

# 函数需要参数装饰器怎么写
def demo(value):
    print(value)
    def getTime(func):
        def inner(*args, **kwargs):
            start_time = time.time()
            func(*args, **kwargs)
            end_time = time.time()
            print("函数执行耗时：{}".format(end_time-start_time))
        return inner
    return getTime

@demo("abc")
def addNum(a, b):
    print("计算结果是：{}".format(a+b))
    time.sleep(2)

addNum(10, 15)

@demo("你好")
def func_001():
    print("执行函数func——001")
    time.sleep(1)

func_001()